﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using InHD.viewmodels;
using InHD.ui.windows;
using System.Configuration;

namespace InHD
{
    public class InhdApp:Application
    {
        public InHD.ui.windows.MainWindow MainUI { get; private set; }
        public InHD.ui.windows.Login loginUI { get; private set; }

        public InhdApp()
            : base()
        {
            string culture = ConfigurationManager.AppSettings["appCulture"];
            // culture = "en-US";

            System.Threading.Thread.CurrentThread.CurrentUICulture =
                new System.Globalization.CultureInfo(culture);
            System.Threading.Thread.CurrentThread.CurrentCulture =
                new System.Globalization.CultureInfo(culture);
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            //this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
            //Login LogonDlg = new Login("", "");
            //LogonDlg.ShowDialog();
            //if (!true)
            //{
            //    //Shutdown();
            //}
            //else
            //{
            ShutdownMode = ShutdownMode.OnExplicitShutdown;

            loginUI = new InHD.ui.windows.Login();
            var loginModel = new LoginViewModel();
            loginModel.RequestClose += (x, y) => { loginUI.Close(); };
            loginUI.DataContext = loginModel;
            loginUI.ShowDialog();

            if (Current != null)
            {
                Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
                if (!string.IsNullOrEmpty(loginModel.CurrentUserUNK))
                {
                    MainUI = new InHD.ui.windows.MainWindow();
                    MainUI.DataContext = new MainViewModel(loginModel.CurrentStaff);
                    MainUI.Show();
                }
                else
                {
                    Current.Shutdown();
                }
            }


            //}
        }
    }
}
